package com.jt.chapter01.service;

import com.jt.chapter01.entity.User;
import com.jt.chapter01.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author jiang tao
 * @date 2022/1/6
 * @description:
 **/
@Service
public class MyUserDetailsService implements UserDetailsService {
    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.getUser(username);
        if(user == null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        System.out.println("找到用户");
        return user;
    }
}
